/*******************************************************************************
 * Copyright (c) 2006 Ultimate Technology, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Bojan Vukojevic - initial API and implementation
 *******************************************************************************/
package com.ultimatetech.cim.views.content;

import java.util.Enumeration;

import javax.wbem.cim.CIMException;
import javax.wbem.cim.CIMObjectPath;
import javax.wbem.client.CIMClient;

import org.eclipse.core.runtime.Preferences;

import com.ultimatetech.cim.preferences.CIMPreferencePage;

public class CIMQuery {
	Preferences pref = null;
	CIMClient client = null;
	public CIMQuery(Preferences p) {		
		pref = p;		
	}
	
	public Enumeration execute(String q) throws CIMException {
		Enumeration en = null;
		try {
			client = CIMConnect.connect(
				pref.getString(CIMPreferencePage.PreferenceNames.IS_SECURE),
				pref.getString(CIMPreferencePage.PreferenceNames.CIM_HOST),
				pref.getString(CIMPreferencePage.PreferenceNames.CIM_PORT),
				pref.getString(CIMPreferencePage.PreferenceNames.CIM_NAMESPACE)
				);	
			//CIMObjectPath cop = new CIMObjectPath()
			en = client.execQuery(new CIMObjectPath(), q, CIMClient.WQL);			
		} finally {
			client.close();
		}
		return en;
	}
}
